home *** CD-ROM | disk | FTP | other *** search
/ Atari Forever 4 / Atari Forever 4.zip / Atari Forever 4.iso / PD_THEMA / EDITOREN / 7UP_PD / PREVIEW2.C < prev    next >
C/C++ Source or Header  |  1998-03-14  |  8KB  |  332 lines

  1. /* Textvorschau (kein Fensterdialog, nicht auto-redraw-fähig) */
  2. /*****************************************************************************
  3. *
  4. *                                                7UP
  5. *                                        Modul: PREVIEW.C
  6. *                                      (c) by TheoSoft '91
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #include <aes.h>
  15. #include <vdi.h>
  16.  
  17. #include "windows.h"
  18. #include "forms.h"
  19. #include "7UP.H"
  20. #include "alert.h"
  21.  
  22. #define FF 12
  23. #if GEMDOS
  24. #define HI 16
  25. #else
  26. #define HI 14
  27. #endif
  28. #define LO  8
  29.  
  30. #define FLAGS15 0x8000
  31.  
  32. extern int zl,bl,or,kz,fz,ur,lr,zz;
  33. extern int aeshandle,boxh;
  34. extern char alertstr[];
  35.  
  36. int MAX_SPALT, BLATTHOEHE, BLATTBREITE;
  37.  
  38. static void set_attr(int handle)
  39. {
  40.     int ret,attr[10];
  41.     
  42.     vswr_mode(handle,MD_REPLACE);             /* transparent */
  43.     vsm_color(handle,BLACK);
  44.     vsm_type(handle,PM_DOT);
  45.     vsf_color(handle,BLACK);
  46.     vsf_style(handle,1);
  47.     vqt_attributes(aeshandle,attr);
  48.     vst_font(handle,attr[0]);  /* Systemfont einstellen */
  49.     vst_point(handle,8,&ret,&ret,&ret,&ret);
  50.     vst_color(handle,BLACK);
  51.     vst_alignment(handle,0,5,&ret,&ret); /* Ausrichtung */
  52. }
  53.  
  54. /* ------------------------------------------------------------ */
  55.  
  56. static void pt_set(int *points, int x, int y)
  57. {
  58.     points[0]=x;
  59.     points[1]=y;
  60. }
  61.  
  62. /* ------------------------------------------------------------ */
  63.  
  64. static void set_pixel(int handle, int cx, int cy)
  65. {
  66.     int pxyarray[4];
  67.     pxyarray[0]= cx;
  68.     pxyarray[1]= cy;
  69.     pxyarray[2]= cx;
  70.     pxyarray[3]= cy;
  71. /*
  72.     v_pmarker(handle,1,pxyarray);
  73. */
  74.     v_pline(handle,2,pxyarray);
  75. }
  76.  
  77. /* ------------------------------------------------------------ */
  78.  
  79. static void draw_seite(int handle, int x_pos, int y_pos) /* Ein leeres "Blatt" an der     */
  80. {
  81.     int x_len=BLATTBREITE,y_len=BLATTHOEHE;
  82.     int points [5][2];
  83.  
  84.     x_pos=x_pos+1;
  85.     y_pos=y_pos+1;
  86. /*
  87.     vsf_color(handle,BLACK);
  88. */
  89.     vsf_interior(handle,FIS_SOLID);
  90.     pt_set(points[0],x_pos,y_pos);
  91.     pt_set(points[1],(x_pos+x_len),y_pos);
  92.     pt_set(points[2],(x_pos+x_len),(y_pos+y_len));
  93.     pt_set(points[3],x_pos,(y_pos+y_len));
  94.     pt_set(points[4],x_pos,y_pos);
  95.     v_fillarea(handle,5,points);
  96.     x_pos=x_pos-1;
  97.     y_pos=y_pos-1;
  98. /*
  99.     vsf_style(handle,1);
  100. */
  101.     vsf_interior(handle,FIS_HOLLOW);
  102.     pt_set(points[0],x_pos,y_pos);
  103.     pt_set(points[1],(x_pos+x_len),y_pos);
  104.     pt_set(points[2],(x_pos+x_len),(y_pos+y_len));
  105.     pt_set(points[3],x_pos,(y_pos+y_len));
  106.     pt_set(points[4],x_pos,y_pos);
  107.     v_fillarea(handle,5,points);
  108. }
  109.  
  110. static int calc_page(OBJECT *tree, int mx, int my, int maxcol, int maxrow, int box, int maxpage)
  111. {                                                /* aus Mausposition Seite berechnen */
  112.     int x,y,page=0;
  113.     
  114.     objc_offset(tree,PREVPAGE,&x,&y);
  115.     mx-=x;
  116.     my-=y;
  117.     page+=mx/(tree[PREVPAGE].ob_width/maxcol);
  118.     page+=my/(tree[PREVPAGE].ob_height/maxrow)*maxcol;
  119.     page+=(maxcol*maxrow*box+1);
  120. /*
  121. printf("\33H|%d|%d|",page,maxpage);
  122. */
  123.     return(page>(maxpage+1)?0:page);
  124. }
  125.  
  126. /* ------------------------------------------------------------ */
  127. void hndl_preview(WINDOW *wp, OBJECT *tree, LINESTRUCT *begcut, LINESTRUCT *endcut)
  128. {
  129.     LINESTRUCT *line;
  130.     int ret,pxyarray[4];
  131.     register int i,k,m,exit_obj=0;
  132.     long *pagedesc;
  133.     
  134.     int cx,cy;  /* Zeichenposition */
  135.     int px,py;  /* Seitenposition  */
  136.     int mx,my;    /* Mausposition für Klick */
  137.     
  138.     int zeile=0,
  139.          spalte=0;
  140.     int col,maxcol,
  141.          row,maxrow,
  142.          box,maxbox;
  143.     int page=0;
  144.     long gotoline=0;
  145.     int gotopage=0;
  146.     
  147.     long lines,chars;
  148.     extern int userhandle;
  149.     
  150.     line=wp->fstr;
  151.     Wtxtsize(wp,&lines,&chars);                         /* ganzer Text... */
  152.  
  153.     if(begcut && endcut)
  154.     {
  155.         line=begcut;
  156.         Wblksize(wp,begcut,endcut,&lines,&chars);  /* ...oder Block */
  157.     }
  158.  
  159.     if((pagedesc = malloc(lines*sizeof(long)))==NULL)
  160.     {
  161.         form_alert(1,Apreview[1]);
  162.         return;
  163.     }
  164.  
  165.     BLATTHOEHE=2*bl;
  166.     BLATTBREITE=lr+zl+2;
  167.     MAX_SPALT=BLATTBREITE-lr;
  168.  
  169.     maxcol=(tree->ob_width-(tree[PREVOK].ob_width+2*24))/(BLATTBREITE+4);  /* Anzahlder Blätter */
  170.     maxrow=(tree->ob_height-2*tree[1].ob_height)/(BLATTHOEHE+4); /* Reihen */
  171.     maxbox=(int)(lines%(long)(maxrow*maxcol) ?             /* Anzahl der Durchgänge */
  172.                       lines/(long)(maxrow*maxcol)+1 :
  173.                      lines/(long)(maxrow*maxcol));
  174.  
  175.     tree->ob_flags|=FLAGS15; /* kein Fensterdialog */
  176.  
  177.     tree[PREVPAGE].ob_spec.obspec.framesize=0;
  178.     tree[PREVPAGE].ob_y++; /* ein Pixel tiefer wg. Ü-Unterstreichung */
  179.     
  180.     form_write(tree,PREVNAME,(char *)Wname(wp),FALSE);
  181.     form_exopen(tree,0);
  182.     graf_mouse(M_OFF,NULL);
  183.  
  184.     pxyarray[0]=tree->ob_x;
  185.     pxyarray[1]=tree->ob_y;
  186.     pxyarray[2]=tree->ob_x+tree->ob_width-1;
  187.     pxyarray[3]=tree->ob_y+tree->ob_height-1;
  188.     vs_clip(userhandle,TRUE,pxyarray);
  189.  
  190.     set_attr(userhandle);
  191.     
  192.     px=tree->ob_x+24;  /* Blattpositionen */
  193.     py=tree->ob_y+3*(boxh>8?HI:LO)-1;
  194.     cx=px+lr;              /* Zeichenpositionen */
  195.     cy=py+2*(or+kz);
  196.  
  197.     for(box=0, i=0; box<maxbox; box++, i++)
  198.     {
  199.         for(row=0, k=0; row<maxrow; row++, k++)
  200.         {
  201.             for(col=0, m=0; col<maxcol; col++, m++)
  202.             {
  203.                 draw_seite(userhandle,px,py);
  204.                 pagedesc[page]=gotoline+1;
  205.                 for(zeile=0; line && zeile<zz; line=line->next, zeile++)
  206.                 {
  207.                     gotoline++;
  208.                     for(spalte=0; spalte<MAX_SPALT; spalte++)
  209.                     {
  210.                         switch(line->string[spalte])
  211.                         {
  212.                             case 0:
  213.                                 spalte=MAX_SPALT;
  214.                                 if(((begcut&&endcut) ? line==endcut : !line->next))
  215.                                 {
  216.                                     zeile=zz;
  217.                                     col=maxcol;
  218.                                     row=maxrow;
  219.                                     box=maxbox;
  220.                                 }
  221.                                 break;
  222.                             case FF:
  223.                                 spalte=MAX_SPALT;
  224.                                 zeile=zz;
  225.                                 if(((begcut&&endcut) ? line==endcut : !line->next))
  226.                                 {
  227.                                     col=maxcol;
  228.                                     row=maxrow;
  229.                                     box=maxbox;
  230.                                 }
  231.                                 break;
  232.                             case ' ':
  233.                                 break;
  234.                             default:
  235.                                 set_pixel(userhandle,cx,cy);
  236.                                 break;
  237.                         }
  238.                         cx++;
  239.                     }
  240.                     cx=px+lr;
  241.                     cy=cy+2;
  242.                 }
  243.                 sprintf(alertstr,"%d",++page);
  244.                 v_gtext(userhandle,px+1,py+2,alertstr);
  245.                 px=px+BLATTBREITE+4;
  246.                 cx=px+lr;
  247.                 cy=py+2*(or+kz);
  248.             }
  249.             px=tree->ob_x+24;
  250.             py=py+BLATTHOEHE+4;
  251.             cx=px+lr;
  252.             cy=py+2*(or+kz);
  253.         }
  254.         if(box<maxbox)
  255.         {
  256.             graf_mouse(M_ON,NULL);        /* evtl. beeenden */
  257.             do
  258.             {
  259.                 exit_obj=form_exdo(tree,0)&0x7FFF;
  260.                 switch(exit_obj)
  261.                 {
  262.                     case PREVPAGE:
  263.                         graf_mkstate(&mx,&my,&ret,&ret);
  264.                         gotopage=calc_page(tree,mx,my,maxcol,maxrow,box,page-1);
  265.                         if(gotopage)
  266.                             goto ENDE;
  267.                         objc_update(tree,PREVPAGE,0);
  268.                         break;
  269.                     case PREVHELP:
  270.                         form_alert(1,Apreview[0]);
  271.                         objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,
  272.                             tree->ob_width,tree->ob_height,tree[exit_obj].ob_state&~SELECTED,TRUE);
  273.                         break;
  274.                     case PREVOK:
  275.                          objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,
  276.                             tree->ob_width,tree->ob_height,NORMAL,TRUE);
  277.                         objc_update(tree,PREVPAGE,0);
  278.                         break;
  279.                     case PREVABBR:
  280.                          objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,
  281.                             tree->ob_width,tree->ob_height,NORMAL,TRUE);
  282.                         goto ENDE;
  283.                         break;
  284.                 }
  285.             }
  286.             while(exit_obj==PREVHELP);
  287.             graf_mouse(M_OFF,NULL);
  288.             px=tree->ob_x+24;  /* Blattpositionen */
  289.             py=tree->ob_y+3*(boxh>8?HI:LO)-1;
  290.             cx=px+lr;            /* Zeichenpositionen */
  291.             cy=py+2*(or+kz);
  292.             pxyarray[0]=tree->ob_x;
  293.             pxyarray[1]=tree->ob_y;
  294.             pxyarray[2]=tree->ob_x+tree->ob_width-1;
  295.             pxyarray[3]=tree->ob_y+tree->ob_height-1;
  296.             vs_clip(userhandle,TRUE,pxyarray);
  297.         
  298.             set_attr(userhandle);
  299.         }
  300.     }
  301.     graf_mouse(M_ON,NULL);
  302.     do
  303.     {
  304.         exit_obj=form_exdo(tree,0)&0x7FFF;
  305.         switch(exit_obj)
  306.         {
  307.             case PREVPAGE:
  308.                 graf_mkstate(&mx,&my,&ret,&ret);
  309.                 gotopage=calc_page(tree,mx,my,maxcol,maxrow,i-1,page-1);
  310.                 if(gotopage)
  311.                       goto ENDE;
  312.                 break;
  313.             case PREVHELP:
  314.                 form_alert(1,Apreview[0]);
  315.                 objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,
  316.                     tree->ob_width,tree->ob_height,tree[exit_obj].ob_state&~SELECTED,TRUE);
  317.                 break;
  318.         }
  319.     }
  320.     while(exit_obj==PREVHELP || exit_obj==PREVPAGE);
  321. ENDE:
  322.     form_exclose(tree,exit_obj,0);
  323.     tree[PREVPAGE].ob_y--; /* ein Pixel wieder höher wg. Ü-Unterstreichung */
  324.     vs_clip(userhandle,FALSE,pxyarray);
  325.     if(gotopage)
  326.     {
  327.         hndl_goto(wp,NULL,pagedesc[gotopage-1]);
  328.     }
  329.     free(pagedesc);
  330.     return;
  331. }
  332.